package difangame.sprite;

/**
 * @author kathleen
 */
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;
import difangame.Constants;
import framework.Level;


public class Bug extends Clinger {
    private final String myImageFile = "player.png";
    private final int myWidth = 23;
    private final int myHeight = 30;

    private int dy = 7;
    private int dx = 3;
    private Map<String, Point> keyTriggeredMoves;

    public Bug () {
        pointValue = 0;
    }

    @Override
    public void initialize (Point p, Level l) {
        super.superInitialize(p, myImageFile, myWidth, myHeight, l);
        setUpKeyMap();
        setMyName(Constants.bug);
    }

    @Override
    public void move () {
        String lastKey = getMyLevel().getMyGame().getMyContainer().getLastKeyPressed();
        if (keyTriggeredMoves.containsKey(lastKey)) {
            Point p = keyTriggeredMoves.get(lastKey);
            setMyCenter(new Point(getMyCenter().x + p.x, getMyCenter().y + p.y));
        }
        else {
            moveWithCarrier();
        }
    }

    private void setUpKeyMap () {
        keyTriggeredMoves = new HashMap<String, Point>();
        keyTriggeredMoves.put(Constants.Down, new Point(0, dy));
        keyTriggeredMoves.put(Constants.Up, new Point(0, -dy));
        keyTriggeredMoves.put(Constants.Left, new Point(-dx, 0));
        keyTriggeredMoves.put(Constants.Right, new Point(dx, 0));
    }

    public boolean matchesMyCarrierName (String s) {
        return s.equals(myCarrier.getMyName());
    }

}
